import {
  CreateDateColumn,
  DeleteDateColumn,
  PrimaryGeneratedColumn,
  UpdateDateColumn,
  VersionColumn
} from 'typeorm';

export class BaseEntity {
  @PrimaryGeneratedColumn('uuid', { comment: '主键编码' })
  id: string;

  @CreateDateColumn({
    type: 'timestamp',
    name: 'create_time',
    comment: '创建时间'
  })
  createTime?: Date;

  @UpdateDateColumn({
    type: 'timestamp',
    name: 'update_time',
    comment: '更改时间'
  })
  updateTime?: Date;

  @DeleteDateColumn({
    type: 'timestamp',
    name: 'delete_time',
    default: null,
    comment: '删除时间'
  })
  deleteTime?: Date;

  @VersionColumn({
    type: 'int',
    comment: '版本号，防止读写不同步',
    select: false,
    default: 1
  })
  version?: number;
}
